#!/bin/bash

# 第一 程序
echo "Stop gateway : gateway-1.0-SNAPSHOT.jar"
pid=`ps -ef |grep java|grep gateway-1.0-SNAPSHOT.jar | awk '{print $2}'`
echo 'old Procedure pid:'$pid
if [ -n "$pid" ]
then
kill -9 $pid
fi

# 第二 程序
echo "Stop user: user-1.0-SNAPSHOT.jar"
pid=`ps -ef |grep java|grep user-1.0-SNAPSHOT.jar | awk '{print $2}'`
echo 'old Procedure pid:'$pid
if [ -n "$pid" ]
then
kill -9 $pid
fi

# 第三 程序
echo "Stop goods: goods-1.0-SNAPSHOT.jar"
pid=`ps -ef |grep java|grep goods-1.0-SNAPSHOT.jar | awk '{print $2}'`
echo 'old Procedure pid:'$pid
if [ -n "$pid" ]
then
kill -9 $pid
fi

# 第四 程序
echo "Stop orders: orders-1.0-SNAPSHOT.jar"
pid=`ps -ef |grep java|grep orders-1.0-SNAPSHOT.jar | awk '{print $2}'`
echo 'old Procedure pid:'$pid
if [ -n "$pid" ]
then
kill -9 $pid
fi


path=/home/jenkins/prod/shixunsan-houduan

if [ -d "$path" ]; then
    echo "路径 $path 存在。"
else
    echo "路径 $path 不存在。"
    mkdir -p /home/jenkins/prod
fi
# cd 到当前目录
cd $path
echo ' pwd : $PWD '

 #  判断当前路径是否存在

if [ -d "$path/p14-buy-java" ]; then
    echo "路径 $path/p14-buy-java 存在。"
else
    echo "路径 $path/p14-buy-java 不存在。"
    git clone https://gitee.com/xiaoyuniu/shixunsan-houduan.git
fi
#  获取git 最新代码
cd $path/p14-buy-java

git pull origin master

#  打包
mvn clean package -Dmaven.test.skip=true

echo " mvn clean package -U -Dmaven.test.skip=true ： ---- ok ----"

echo "  ----------------------------------------  start  -------------------------------------------------------------------"
echo " user 和  gateway 开始启动-----------OK------------------- "
cd $path/p14-buy-java/gateway/target/
echo "进出入工程目录gateway : $PWD"
nohup java -Dspring.cloud.nacos.discovery.ip=113.44.137.179 -jar $javaOPS gateway-1.0-SNAPSHOT.jar > gateway.log 2>&1 &

cd $path/p14-buy-java/user/target/
echo "进出入工程目录 user : $PWD"
nohup java -Dspring.cloud.nacos.discovery.ip=113.44.137.179 -jar $javaOPS user-1.0-SNAPSHOT.jar > user.log 2>&1 &

echo " user 和  gateway 成功 -----------OK------------------- "


echo " goods 和  orders 开始启动-----------OK------------------- "
cd $path/p14-buy-java/goods/target/
echo "进出入工程目录card : $PWD"
nohup java -Dspring.cloud.nacos.discovery.ip=113.44.137.179 -jar $javaOPS goods-1.0-SNAPSHOT.jar > goods.log 2>&1 &



cd $path/orders/orders/target/
echo "进出入工程目录 orders : $PWD"
nohup java -Dspring.cloud.nacos.discovery.ip=113.44.137.179 -jar $javaOPS orders-1.0-SNAPSHOT.jar > orders.log 2>&1 &

echo " orders 和  goods 成功 -----------OK------------------- "


#echo " goos 和  messages 开始启动-----------OK------------------- "

#cd $path/usian-leadnews/usian-leadnews-goos/target/
#echo "进出入工程目录goos : $PWD"
#nohup java -jar $javaOPS usian-leadnews-goos-1.0-SNAPSHOT.jar > goos.log 2>&1 &

#cd $path/usian-leadnews/usian-leadnews-messages/target/
#echo "进出入工程目录messages : $PWD"
#nohup java -jar $javaOPS usian-leadnews-messages-1.0-SNAPSHOT.jar > messages.log 2>&1 &

#echo " goos 和  messages 成功 -----------OK------------------- "


#echo " security 和  xingcheng 开始启动-----------OK------------------- "

#cd $path/usian-leadnews/usian-leadnews-security/target/
#echo "进出入工程目录security : $PWD"
#nohup java -jar $javaOPS usian-leadnews-security-1.0-SNAPSHOT.jar > security.log 2>&1 &

#cd $path/usian-leadnews/usian-leadnews-xingcheng/target/
#echo "进出入工程目录xingcheng : $PWD"
#nohup java -Dspring.cloud.nacos.discovery.ip=8.140.238.50 -jar $javaOPS usian-leadnews-xingcheng-1.0-SNAPSHOT.jar > xingcheng.log 2>&1 &

#echo " security 和  xingcheng 成功 -----------OK------------------- "



echo '-----------------------------------------success--------------------------------------------------'




